﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using HouseAgencySite.Models;
using HouseAgencySite.ViewModel;

namespace HouseAgencySite.Areas.Admin.Controllers
{
     [SessionState(SessionStateBehavior.Required)]
    public class BaseController : Controller
    {
        private LogUserInfo _CurrentUser = new LogUserInfo();

        /// <summary>
        /// 当前用户信息
        /// </summary>
        public LogUserInfo CurrentUser 
        {
            get
            {
                return Session["UserInfo"] == null ? _CurrentUser : Session["UserInfo"] as LogUserInfo;
            }
            set
            {
                _CurrentUser = value;
            }
        }
        //session过期提示重新登录

        //protected override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    if (filterContext.HttpContext.Session != null)
        //    {
        //        //if (HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName] == null)
        //        //{
        //        //    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Account", Action = "Login" }));
        //        //}
        //        if (filterContext.HttpContext.Session.IsNewSession)
        //        {
        //            if (filterContext.HttpContext.Session["UserInfo"] == null)
        //            {
        //                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Account", Action = "Login" }));
        //            }
        //            else
        //            {
        //                LogUserInfo user = filterContext.HttpContext.Session["UserInfo"] as LogUserInfo;
        //                if (user == null || string.IsNullOrEmpty(user.Guid))
        //                {
        //                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Account", Action = "Login" }));
        //                }
        //            }

        //        }
        //    }
        //}
        
    }
}
